package com.fyzk.activity.lottery.gaopin;

import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.activity.app.AppToast;
import com.fyzk.activity.down_numhistory.NumHistoryPrizeView;
import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.activity.lottery.shuzicai.LotteryBaseActivity;
import com.fyzk.activity.lottery.shuzicai.SelectBallView;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper.BallClickListener;
import com.fyzk.activity.lottery.shuzicai.TouZhuHelper.BallItemClickLitener;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupItemBean;
import com.fyzk.activity.lottery.shuzicai.klpk.KLPKPopupwindow;
import com.fyzk.activity.myview.BallPopFrameLayout;
import com.fyzk.activity.myview.BallScrollView;
import com.fyzk.activity.myview.DrawBallFrameLayout;
import com.fyzk.activity.myview.WeiZhi;
import com.fyzk.activity.trend.SSCTrendActivity;
import com.fyzk.bean.PrizeHistoryItem;
import com.fyzk.betzhushu.ZhuShuFactory;
import com.fyzk.data.AppLotteryInfos;
import com.fyzk.random.RandomFactory;
import com.fyzk.utils.HelpUrlConstants;
import com.fyzk.utils.IntentParamUtils;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.utils.RandomUtil;
import com.fyzk.view.BottomView;
import com.fyzk.view.BottomView.onBottomClickListener;
import com.fyzk.view.TopTitleView;
import com.fyzk.view.ViewCallBack;
import com.tyjc.lottery.R;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

@ContentView(R.layout.ac_shishicai)
public class SSCActivity extends LotteryBaseActivity implements KLPKPopupwindow.KLPKPopuponItemListener,
        BallItemClickLitener, BallClickListener, onBottomClickListener {

    private TopTitleView topView;

    private int[] popup_itemsId = {R.string.gp_ssc_yx, R.string.gp_ssc_ex, R.string
            .gp_ssc_ex_zuxuan, R.string.gp_ssc_sx, R.string.gp_ssc_zusan_danshi, R.string
            .gp_ssc_zusan_fushi,
            R.string.gp_ssc_zuliu, R.string.gp_ssc_wx, R.string.gp_ssc_wxtx, R.string.gp_ssc_dxds};

    private String[] popup_itemsStr2 = {"奖金","奖金","奖金","奖金","奖金","奖金",
            "奖金","奖金","奖金","奖金"};
    private String[] popup_itemsStr3 = {"10米","100米","50米","1000米","320米","320米",
            "160米","100000米","20440米","4米"};
    protected KLPKPopupwindow top_popup;
    protected List<KLPKPopupItemBean> popup_items = new ArrayList<>();

    private final int ONE_STAR_COMMON = 0x0;// 一星直选
    private final int TWO_STAR_COMMON = 0x1;// 二星直选
    private final int TWO_STAR_Group = 0x2;// 二星组选
    private final int THREE_STAR_COMMON = 0x3;// 三星直选
    private final int THREE_STAR_GROUP_DAN = 0x4;// 三星组三单式
    private final int THREE_STAR_GROUP_FU = 0x5;// 三星组三复式
    private final int THREE_STAR_GROUP_LIU = 0x6;// 三星组六
    private final int FIVE_STAR_COMMON = 0x7;// 五星直选
    private final int FIVE_STAR_TONG = 0x8;// 五星通选
    private final int FIVE_STAR_DXDS = 0x9;// 大小单双

    private SelectBallView ballView_one;
    private SelectBallView ballView_two;
    private SelectBallView ballView_three;
    private SelectBallView ballView_four;
    private SelectBallView ballView_five;
    private SelectBallView ballView_dxds_shi;
    private SelectBallView ballView_dxds_ge;
    private SelectBallView ballView_zu3_double;
    private SelectBallView ballView_zu3_single;

    private TextView txt_title1;
    private TextView txt_title2;
    private TextView txt_title3;
    private TextView txt_title4;
    private TextView txt_title5;
    private TextView txt_title6;
    private TextView txt_title7;

    private int ball_count = 10;

    private List<BallInfo> balls_firstLine = new ArrayList<BallInfo>();
    private List<BallInfo> balls_twoLine = new ArrayList<BallInfo>();
    private List<BallInfo> balls_threeLine = new ArrayList<BallInfo>();
    private List<BallInfo> balls_fourLine = new ArrayList<BallInfo>();
    private List<BallInfo> balls_fiveLine = new ArrayList<BallInfo>();
    private List<BallInfo> balls_dxds_shi = new ArrayList<BallInfo>();
    private List<BallInfo> balls_dxds_ge = new ArrayList<BallInfo>();

    private LinearLayout mLl_one;
    private LinearLayout mLl_two;
    private LinearLayout mLl_three;
    private LinearLayout mLl_four;
    private LinearLayout mLl_five;
    private LinearLayout mLl_shi;
    private LinearLayout mLl_ge;
    private LinearLayout mLl_zu3;

    // 底部
    private BottomView bottomView;
    private BallScrollView ball_scroll;
    private DrawBallFrameLayout ball_linear;
    private BallPopFrameLayout moveQiu;

    @ViewInject(R.id.shake_random_ll)
    LinearLayout shake_random_ll;

    private TextView prize_tishi_tv;    // 奖金提示

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        shake_random_ll.setOnClickListener(this);
        init();
        ViewCallBack.getInstance().AttachCountDownObj(this);
        popupClickItem(popupId);
        ballClick();
    }

    @Override
    public TopTitleView getTopView() {
        return topView;
    }

//    protected String[] getMenuItems() {
//        return new String[]{"开奖公告", "玩法介绍","投注查询"};
//    }

    @Override
    protected void init() {
        // TODO Auto-generated method stub
        super.init();
        for (int i = 0; i < popup_itemsId.length; i++) {

            KLPKPopupItemBean itemBean = new KLPKPopupItemBean();
            itemBean.str1 = getString(popup_itemsId[i]);
            itemBean.str2 = popup_itemsStr2[i];
            itemBean.str3 = popup_itemsStr3[i];
            popup_items.add(itemBean);
        }
        top_popup = new KLPKPopupwindow(this, AbsListView.LayoutParams.MATCH_PARENT, AbsListView
                .LayoutParams.WRAP_CONTENT,
                popup_items, popup_items.size());
        top_popup.setHm_PopupOnItemListener(this);
        topView = (TopTitleView) findViewById(R.id.ssc_topTitle);
        topView.setOnTitleClickListener(this);
        topView.setJianTouVisible(View.VISIBLE);
        topView.setRightImg(R.drawable.downmenu_icon);
        topView.setRight2Visible(View.VISIBLE);
        topView.getRightImg2().setImageDrawable(getResources().getDrawable(R.drawable.icon_refresh));
        topView.setCenterText(popup_items.get(popupId).str1);
        top_popup.setCheckItem(popupId);

        ll_history = (LinearLayout) findViewById(R.id.ssc_ball_history);
        ball_linear = (DrawBallFrameLayout) findViewById(R.id.ssc_drawball_framelayout);
        ball_scroll = (BallScrollView) findViewById(R.id.ssc_ballscroll);
        moveQiu = (BallPopFrameLayout) findViewById(R.id.ssc_fl_moveqiu);
        ball_linear.setScr(ball_scroll);
        ball_linear.setFl_moveqiu(moveQiu);
        ball_linear.setUpOrDownListener(this);
        ball_linear.setLayerType(View.LAYER_TYPE_SOFTWARE,null);

        ballView_one = (SelectBallView) findViewById(R.id.ssc_ballview_first);
        ballView_two = (SelectBallView) findViewById(R.id.ssc_ballview_two);
        ballView_three = (SelectBallView) findViewById(R.id.ssc_ballview_three);
        ballView_four = (SelectBallView) findViewById(R.id.ssc_ballview_four);
        ballView_five = (SelectBallView) findViewById(R.id.ssc_ballview_five);
        ballView_dxds_shi = (SelectBallView) findViewById(R.id.ssc_ballview_dxds_shi);
        ballView_dxds_ge = (SelectBallView) findViewById(R.id.ssc_ballview_dxds_ge);
        ballView_zu3_double = (SelectBallView) findViewById(R.id.ssc_ballview_zu3_double);
        ballView_zu3_single = (SelectBallView) findViewById(R.id.ssc_ballview_zu3_single);

        txt_title1 = (TextView) findViewById(R.id.ssc_title_1);
        txt_title2 = (TextView) findViewById(R.id.ssc_title_2);
        txt_title3 = (TextView) findViewById(R.id.ssc_title_3);
        txt_title4 = (TextView) findViewById(R.id.ssc_title_4);
        txt_title5 = (TextView) findViewById(R.id.ssc_title_5);
        txt_title6 = (TextView) findViewById(R.id.ssc_title_6);
        txt_title7 = (TextView) findViewById(R.id.ssc_title_7);

        TouZhuHelper.getInstance().setBallClickListener(this);

        TouZhuHelper.getInstance().setBallItemClickLitener(this);

        initArrayInfos();

        ballView_zu3_double.setSelect_max(1);
        ballView_zu3_single.setSelect_max(1);
        ballView_zu3_double.setGuanLian_view(ballView_zu3_single);
        ballView_zu3_single.setGuanLian_view(ballView_zu3_double);

        mLl_one = (LinearLayout) findViewById(R.id.linear_ssc_one);
        mLl_two = (LinearLayout) findViewById(R.id.linear_ssc_two);
        mLl_three = (LinearLayout) findViewById(R.id.linear_ssc_three);
        mLl_four = (LinearLayout) findViewById(R.id.linear_ssc_four);
        mLl_five = (LinearLayout) findViewById(R.id.linear_ssc_five);
        mLl_shi = (LinearLayout) findViewById(R.id.linear_ssc_dxds_shi);
        mLl_ge = (LinearLayout) findViewById(R.id.linear_ssc_dxds_ge);
        mLl_zu3 = (LinearLayout) findViewById(R.id.linear_ssc_zu3);

        bottomView = (BottomView) findViewById(R.id.ssc_bottom);
        bottomView.setRightText("确定");
        bottomView.setLeftText("清除");
        bottomView.setonBottomClickListener(this);
        bottomView.setMoRenText1(0 + "注 ");
        bottomView.setMoRenText2("共" + 0 + "米");

        prize_tishi_tv = (TextView) findViewById(R.id.prize_tishi_tv);
    }

    @Override
    protected void initArrayInfos() {
        if (arr_infos.size() == 7) {
            initBallList(balls_firstLine, ball_count, 0, false);
            initBallList(balls_twoLine, ball_count, 0, false);
            initBallList(balls_threeLine, ball_count, 0, false);
            initBallList(balls_fourLine, ball_count, 0, false);
            initBallList(balls_fiveLine, ball_count, 0, false);
            initDXDSBalls(balls_dxds_shi);
            initDXDSBalls(balls_dxds_ge);

            balls_firstLine = arr_infos.get(0);
            balls_twoLine = arr_infos.get(1);
            balls_threeLine = arr_infos.get(2);
            balls_fourLine = arr_infos.get(3);
            balls_fiveLine = arr_infos.get(4);
            balls_dxds_shi = arr_infos.get(5);
            balls_dxds_ge = arr_infos.get(6);

        } else {
            arr_infos.clear();
            initBallList(balls_firstLine, ball_count, 0, false);
            initBallList(balls_twoLine, ball_count, 0, false);
            initBallList(balls_threeLine, ball_count, 0, false);
            initBallList(balls_fourLine, ball_count, 0, false);
            initBallList(balls_fiveLine, ball_count, 0, false);

            initDXDSBalls(balls_dxds_shi);
            initDXDSBalls(balls_dxds_ge);

            arr_infos.add(balls_firstLine);
            arr_infos.add(balls_twoLine);
            arr_infos.add(balls_threeLine);
            arr_infos.add(balls_fourLine);
            arr_infos.add(balls_fiveLine);
            arr_infos.add(balls_dxds_shi);
            arr_infos.add(balls_dxds_ge);
        }

        ballView_one.setBallInfoList(balls_firstLine);
        ballView_two.setBallInfoList(balls_twoLine);
        ballView_three.setBallInfoList(balls_threeLine);
        ballView_four.setBallInfoList(balls_fourLine);
        ballView_five.setBallInfoList(balls_fiveLine);
        ballView_dxds_shi.setBallInfoList(balls_dxds_shi);
        ballView_dxds_ge.setBallInfoList(balls_dxds_ge);
        ballView_zu3_double.setBallInfoList(balls_firstLine);
        ballView_zu3_single.setBallInfoList(balls_twoLine);
    }

    private String[] dxds = {"大", "小", "单", "双"};

    private void initDXDSBalls(List<BallInfo> balls) {
        balls.clear();
        for (int i = 0; i < dxds.length; i++) {
            BallInfo info = new BallInfo(dxds[i]);
            info.setSelected(false);
            balls.add(info);
        }
    }

    @Override
    public void onLeftClick() {
        // TODO Auto-generated method stub
        finish();
    }

    @Override
    public void onCenterClick() {
        // TODO Auto-generated method stub
        top_popup.showPopupWindow(topView);
    }

    @Override
    public void onRightClick() {
        // TODO Auto-generated method stub
        toHelp();
    }

    @Override
    public boolean touZhu() {
        // TODO Auto-generated method stub
        long zhuShu = getZhushu();
        if (zhuShu > 0) {
            int lotteryId = wanFaId;
            switch (wanFaId) {
                case LotteryIDUtils.GPSSC_LOTTERY_ID_YX_DAN_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.GPSSC_LOTTERY_ID_YX_FU_INT;
                    }
                    break;
                case LotteryIDUtils.GPSSC_LOTTERY_ID_EX_DAN_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.GPSSC_LOTTERY_ID_EX_FU_INT;
                    }
                    break;
                case LotteryIDUtils.GPSSC_LOTTERY_ID_SX_DAN_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.GPSSC_LOTTERY_ID_SX_FU_INT;
                    }
                    break;
                case LotteryIDUtils.GPSSC_LOTTERY_ID_ZUSAN_BAO_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.GPSSC_LOTTERY_ID_ZUSAN_BAO_INT;
                    }
                    break;
                case LotteryIDUtils.GPSSC_LOTTERY_ID_WX_DAN_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.GPSSC_LOTTERY_ID_WX_FU_INT;
                    }
                    break;
                case LotteryIDUtils.GPSSC_LOTTERY_ID_ZL_DAN_INT:
                    if (zhuShu > 1) {
                        lotteryId = LotteryIDUtils.GPSSC_LOTTERY_ID_ZULIU_BAO_INT;
                    }
                    break;
            }

            touZhu1(lotteryId, zhuShu);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void clear() {
        bottomView.setMoRenText1(0 + "注 ");
        bottomView.setMoRenText2("共" + 0 + "米");

        initBallList(balls_firstLine, ball_count, 0, false);
        initBallList(balls_twoLine, ball_count, 0, false);
        initBallList(balls_threeLine, ball_count, 0, false);
        initBallList(balls_fourLine, ball_count, 0, false);
        initBallList(balls_fiveLine, ball_count, 0, false);

        initDXDSBalls(balls_dxds_shi);
        initDXDSBalls(balls_dxds_ge);

        ballView_one.setSelect_count(0);
        ballView_two.setSelect_count(0);
        ballView_three.setSelect_count(0);
        ballView_four.setSelect_count(0);
        ballView_five.setSelect_count(0);
        ballView_dxds_shi.setSelect_count(0);
        ballView_dxds_ge.setSelect_count(0);
        ballView_zu3_double.setSelect_count(0);
        ballView_zu3_single.setSelect_count(0);

        ballView_one.invalidate();
        ballView_two.invalidate();
        ballView_three.invalidate();
        ballView_four.invalidate();
        ballView_five.invalidate();
        ballView_dxds_shi.invalidate();
        ballView_dxds_ge.invalidate();
        ballView_zu3_double.invalidate();
        ballView_zu3_single.invalidate();
    }

    @Override
    public int getLotteryId() {
        // TODO Auto-generated method stub
        return LotteryIDUtils.CQSSC_LOTTERY_ID_INT;
    }

    private int curPostion;

    @Override
    protected void popupClickItem(int postion) {
        // TODO Auto-generated method stub
        this.curPostion = postion;
        popupId = postion;
        topView.setCenterText(AppLotteryInfos.getLotteryName(getLotteryId()) + " - "
                + popup_items.get(popupId).str1);
//		clear();
        switch (postion) {
            case ONE_STAR_COMMON:
                prize_tishi_tv.setText(R.string.gp_ssc_prize_yx);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_YX_DAN_INT;
                txt_title1.setText(R.string.text_ge);
                mLl_one.setVisibility(View.VISIBLE);
                ballView_one.setSelect_max(ball_count);
                shake_random_ll.setVisibility(View.VISIBLE);
//			arr_infos.add(balls_firstLine);
                break;
            case TWO_STAR_COMMON:// 二星直选
                prize_tishi_tv.setText(R.string.gp_ssc_prize_ex);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_EX_DAN_INT;
                txt_title1.setText(R.string.text_shi);
                txt_title2.setText(R.string.text_ge);
                mLl_one.setVisibility(View.VISIBLE);
                mLl_two.setVisibility(View.VISIBLE);
                ballView_one.setSelect_max(ball_count);
                ballView_two.setSelect_max(ball_count);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case TWO_STAR_Group:// 二星组选
                prize_tishi_tv.setText(R.string.gp_ssc_prize_ex_zuxuan);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_EX_ZU_INT;
                txt_title1.setText(R.string.gp_11xuan5_balltitle_xuanhao);
                mLl_one.setVisibility(View.VISIBLE);
                ballView_one.setSelect_max(ball_count);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case THREE_STAR_COMMON:// 三星直选
                prize_tishi_tv.setText(R.string.gp_ssc_prize_sx);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_SX_DAN_INT;
                txt_title1.setText(R.string.text_bai);
                txt_title2.setText(R.string.text_shi);
                txt_title3.setText(R.string.text_ge);
                initBallList(balls_firstLine, ball_count, 0, false);
                initBallList(balls_twoLine, ball_count, 0, false);
                initBallList(balls_threeLine, ball_count, 0, false);
                mLl_one.setVisibility(View.VISIBLE);
                mLl_two.setVisibility(View.VISIBLE);
                mLl_three.setVisibility(View.VISIBLE);
                ballView_one.setSelect_max(ball_count);
                ballView_two.setSelect_max(ball_count);
                ballView_three.setSelect_max(ball_count);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case THREE_STAR_GROUP_DAN:// 三星组三单式
                prize_tishi_tv.setText(R.string.gp_ssc_prize_zusan_danshi);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_ZS_DAN_INT;
                showGroupThreeSingle();
                break;
            case THREE_STAR_GROUP_FU:// 三星组三复式
                prize_tishi_tv.setText(R.string.gp_ssc_prize_zusan_fushi);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_ZUSAN_BAO_INT;
                txt_title1.setText(R.string.gp_11xuan5_balltitle_xuanhao);
                mLl_one.setVisibility(View.VISIBLE);
                ballView_one.setSelect_max(ball_count);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case THREE_STAR_GROUP_LIU:// 三星组六
                prize_tishi_tv.setText(R.string.gp_ssc_prize_zuliu);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_ZL_DAN_INT;
                txt_title1.setText(R.string.gp_11xuan5_balltitle_xuanhao);
                mLl_one.setVisibility(View.VISIBLE);
                ballView_one.setSelect_max(ball_count);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case FIVE_STAR_COMMON:// 五星直选
                prize_tishi_tv.setText(R.string.gp_ssc_prize_wx);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_WX_DAN_INT;
                txt_title1.setText(R.string.text_wan);
                txt_title2.setText(R.string.text_qian);
                txt_title3.setText(R.string.text_bai);
                txt_title4.setText(R.string.text_shi);
                txt_title5.setText(R.string.text_ge);
                mLl_one.setVisibility(View.VISIBLE);
                mLl_two.setVisibility(View.VISIBLE);
                mLl_three.setVisibility(View.VISIBLE);
                mLl_four.setVisibility(View.VISIBLE);
                mLl_five.setVisibility(View.VISIBLE);
                ballView_one.setSelect_max(ball_count);
                ballView_two.setSelect_max(ball_count);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case FIVE_STAR_TONG:// 五星通选
                prize_tishi_tv.setText(R.string.gp_ssc_prize_wxtx);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_WXTX_INT;
                txt_title1.setText(R.string.text_wan);
                txt_title2.setText(R.string.text_qian);
                txt_title3.setText(R.string.text_bai);
                txt_title4.setText(R.string.text_shi);
                txt_title5.setText(R.string.text_ge);
                mLl_one.setVisibility(View.VISIBLE);
                mLl_two.setVisibility(View.VISIBLE);
                mLl_three.setVisibility(View.VISIBLE);
                mLl_four.setVisibility(View.VISIBLE);
                mLl_five.setVisibility(View.VISIBLE);
                ballView_one.setSelect_max(ball_count);
                ballView_two.setSelect_max(ball_count);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
            case FIVE_STAR_DXDS:// 大小单双
                prize_tishi_tv.setText(R.string.gp_ssc_prize_dxds);
                dismissAll();
                wanFaId = LotteryIDUtils.GPSSC_LOTTERY_ID_DXDS_INT;
                txt_title6.setText(R.string.text_shi_shuxing);
                txt_title7.setText(R.string.text_ge_shuxing);
                mLl_shi.setVisibility(View.VISIBLE);
                mLl_ge.setVisibility(View.VISIBLE);
//			arr_infos.add(balls_dxds_shi);
//			arr_infos.add(balls_dxds_ge);
                shake_random_ll.setVisibility(View.VISIBLE);
                break;
        }
        addMissValue();
        getMissValueList();
    }

    private void dismissAll() {
        mLl_one.setVisibility(View.GONE);
        mLl_two.setVisibility(View.GONE);
        mLl_three.setVisibility(View.GONE);
        mLl_four.setVisibility(View.GONE);
        mLl_five.setVisibility(View.GONE);
        mLl_shi.setVisibility(View.GONE);
        mLl_ge.setVisibility(View.GONE);
        mLl_zu3.setVisibility(View.GONE);

    }

    private LinearLayout ll_history;

    @Override
    protected void addHistoryView(ArrayList<PrizeHistoryItem> historyItems, boolean isWaitting) {
        // TODO Auto-generated method stub
        ll_history.removeAllViews();
        ll_history.addView(new NumHistoryPrizeView(getContext(), historyItems).getView());
    }

    private void showGroupThreeSingle() {
        mLl_zu3.setVisibility(View.VISIBLE);
//        arr_infos.clear();
//        txt_title1.setText(R.string.text_chonghao);
//        txt_alert1.setText(R.string.text_limit_one);
//        txt_title2.setText(R.string.text_danhao);
//        txt_alert2.setText(R.string.text_limit_one);
//        mLl_one.setVisibility(View.VISIBLE);
//        mLl_two.setVisibility(View.VISIBLE);
//        initBallList(balls_firstLine, ball_count, 0, false);
//        initBallList(balls_twoLine, ball_count, 0, false);
//        arr_infos.add(balls_firstLine);
//        arr_infos.add(balls_twoLine);
//        ballView_zu3_double.setBallInfoList(balls_firstLine);
//        ballView_two.setBallInfoList(balls_twoLine);
//        ballView_one.setSelect_max(1);
//        ballView_two.setSelect_max(1);
//        ballView_one.setGuanLian_view(ballView_two);
//        ballView_two.setGuanLian_view(ballView_one);
        shake_random_ll.setVisibility(View.VISIBLE);
    }

    @Override
    public void randomBallNum() {
        clear();
        switch (curPostion) {
            case ONE_STAR_COMMON:// 一星直选
            {
                int first = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                initBallList(balls_firstLine, ball_count, 0, false);
                balls_firstLine.get(first).setSelected(true);
                ballView_one.invalidate();
                ballClick();
            }
            break;
            case TWO_STAR_COMMON:// 二星直选
            {
                int first = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int two = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                initBallList(balls_firstLine, ball_count, 0, false);
                initBallList(balls_twoLine, ball_count, 0, false);
                balls_firstLine.get(first).setSelected(true);
                balls_twoLine.get(two).setSelected(true);
                ballView_one.invalidate();
                ballView_two.invalidate();
                ballClick();
            }
            break;

            case THREE_STAR_COMMON:// 三星直选
            {
                int first = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int two = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int three = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                initBallList(balls_firstLine, ball_count, 0, false);
                initBallList(balls_twoLine, ball_count, 0, false);
                initBallList(balls_threeLine, ball_count, 0, false);
                balls_firstLine.get(first).setSelected(true);
                balls_twoLine.get(two).setSelected(true);
                balls_threeLine.get(three).setSelected(true);
                ballView_one.invalidate();
                ballView_two.invalidate();
                ballView_three.invalidate();
                ballClick();
            }
            break;

            case THREE_STAR_GROUP_DAN:// 三星组三单式
            {
//                showGroupThreeSingle();
                int[] first = RandomFactory.getRandom(getLotteryId()).randomDanHang(2);
                balls_firstLine.get(first[0]).setSelected(true);
                balls_twoLine.get(first[1]).setSelected(true);
                ballView_zu3_double.invalidate();
                ballView_zu3_single.invalidate();
                ballClick();
            }
            break;
            case TWO_STAR_Group:// 二星组选
            case THREE_STAR_GROUP_FU:// 三星组三复式
            {
                int first[] = RandomFactory.getRandom(getLotteryId()).randomDanHang(2);
                initBallList(balls_firstLine, ball_count, 0, false);
                for (int i = 0; i < first.length; i++) {
                    balls_firstLine.get(first[i]).setSelected(true);
                }
                ballView_one.invalidate();
                ballClick();
            }
            break;
            case THREE_STAR_GROUP_LIU:// 三星组六
            {
                int first[] = RandomFactory.getRandom(getLotteryId()).randomDanHang(3);
                initBallList(balls_firstLine, ball_count, 0, false);
                for (int i = 0; i < first.length; i++) {
                    balls_firstLine.get(first[i]).setSelected(true);
                }
                ballView_one.invalidate();
                ballClick();
            }
            break;
            case FIVE_STAR_COMMON:// 五星直选
            {
                int first = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int two = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int three = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int four = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int five = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                initBallList(balls_firstLine, ball_count, 0, false);
                initBallList(balls_twoLine, ball_count, 0, false);
                initBallList(balls_threeLine, ball_count, 0, false);
                initBallList(balls_fourLine, ball_count, 0, false);
                initBallList(balls_fiveLine, ball_count, 0, false);
                balls_firstLine.get(first).setSelected(true);
                balls_twoLine.get(two).setSelected(true);
                balls_threeLine.get(three).setSelected(true);
                balls_fourLine.get(four).setSelected(true);
                balls_fiveLine.get(five).setSelected(true);
                ballView_one.invalidate();
                ballView_two.invalidate();
                ballView_three.invalidate();
                ballView_four.invalidate();
                ballView_five.invalidate();
                ballClick();
            }
            break;

            case FIVE_STAR_TONG:// 五星通选
            {
                int first = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int two = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int three = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int four = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                int five = RandomFactory.getRandom(getLotteryId()).randomDanHang(1)[0];
                initBallList(balls_firstLine, ball_count, 0, false);
                initBallList(balls_twoLine, ball_count, 0, false);
                initBallList(balls_threeLine, ball_count, 0, false);
                initBallList(balls_fourLine, ball_count, 0, false);
                initBallList(balls_fiveLine, ball_count, 0, false);
                balls_firstLine.get(first).setSelected(true);
                balls_twoLine.get(two).setSelected(true);
                balls_threeLine.get(three).setSelected(true);
                balls_fourLine.get(four).setSelected(true);
                balls_fiveLine.get(five).setSelected(true);
                ballView_one.invalidate();
                ballView_two.invalidate();
                ballView_three.invalidate();
                ballView_four.invalidate();
                ballView_five.invalidate();
                ballClick();
            }
            break;

            case FIVE_STAR_DXDS:// 大小单双
            {
                int[] arr = RandomUtil.randomNoRepeat(1, 0, 3);
                int[] arr_1 = RandomUtil.randomNoRepeat(1, 0, 3);
                initDXDSBalls(balls_dxds_shi);
                initDXDSBalls(balls_dxds_ge);
                balls_dxds_shi.get(arr[0]).setSelected(true);
                balls_dxds_ge.get(arr_1[0]).setSelected(true);
                ballView_dxds_shi.invalidate();
                ballView_dxds_ge.invalidate();
                ballClick();
            }
            break;
        }

    }

    @Override
    public String getHelpUrl() {
        // TODO Auto-generated method stub
        return HelpUrlConstants.Help_SSC;
    }

    @Override
    public String getHelpTitle() {
        // TODO Auto-generated method stub
        return getString(R.string.help_ssc);
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.shake_random_ll:
                randomBallNum();
                break;
        }
    }

    @Override
    public void onItem(int position) {
//        ball_linear.requestingData();
//        topView.setCenterText(popup_items[position]);
        clear();
        popupClickItem(position);
    }

    @Override
    public void popupShow() {
        topView.setJianTouRotate_shun();

    }

    @Override
    public void popupDismiss() {
        topView.setJianTouRotate_ni();

    }

    @Override
    public void ballClick() {
        // TODO Auto-generated method stub
        long zhushu = getZhushu();
        long money = zhushu * 2;

        bottomView.setMoRenText1(zhushu + "注 ");
        bottomView.setMoRenText2("共" + money + "米");
    }

    @Override
    public void ballClick(WeiZhi wz) {
        // TODO Auto-generated method stub
        WeiZhi w = wz;
        // TODO Auto-generated method stub
        int left = w.getLeft() - 5;
        int right = w.getRight() + 5;
        int top = (ball_linear.getY1() - w.getPointY() + w.getTop()) - (w.getBottom() - w.getTop()) - 10;
        int bottom = ball_linear.getY1() - w.getPointY() + w.getTop();
        Rect rect = new Rect(left, top, right, bottom);
        moveQiu.setRect(rect, w.getNum(), w.getType(), w.isShowMoveBall);
    }

    private int wanFaId;

    private long getZhushu() {
        return ZhuShuFactory.getZhuShu(wanFaId).betZhuShu(arr_infos);
    }

    @Override
    public void onBottomLeftClick() {
        // TODO Auto-generated method stub
        clear();
    }

    @Override
    public void onBottomRightClick() {
        // TODO Auto-generated method stub
        if (!touZhu()) {
            AppToast.getToast().show("请先选择一注再投注");
        }
    }

    @Override
    protected void addMissValue() {
        super.addMissValue();
        missKey = AppLotteryInfos.getMissKey2(getLotteryId(), popupId);
//        ball_linear.isDXDS = false;
        switch (popupId) {
            case 0:
                setMissKey(missKey, new String[]{"ge"});
                break;
            case 1:
                setMissKey(missKey, new String[]{"shi","ge"});
                break;
            case 2:
                setMissKey(missKey, new String[]{"miss"});
                break;
            case 3:
                setMissKey(missKey, new String[]{"bai","shi","ge"});
                break;
            case 7:
            case 8:
                setMissKey(missKey, new String[]{"wan","qian","bai","shi","ge"});
                break;
            case 9:
//                ball_linear.isDXDS = true;
                setMissKey(missKey, new String[]{"ge"});
                break;
            default:
                setMissKey(missKey, new String[]{"miss"});
                break;
        }

        if (missInfo != null) {
            switch (popupId) {
                case 0:
                    ballView_one.setMissValues(missInfo.missValue("1007MV_5X").get(4));
                    break;
                case 1:
                    ballView_one.setMissValues(missInfo.missValue("1007MV_5X").get(3));
                    ballView_two.setMissValues(missInfo.missValue("1007MV_5X").get(4));
                    break;
                case 2:
                    ballView_one.setMissValues(missInfo.missValue("1007MV_2ZX").get(0));
                    break;
                case 3:
                    ballView_one.setMissValues(missInfo.missValue("1007MV_5X").get(2));
                    ballView_two.setMissValues(missInfo.missValue("1007MV_5X").get(3));
                    ballView_three.setMissValues(missInfo.missValue("1007MV_5X").get(4));
                    break;
                case 4:
                    ballView_zu3_double.setMissValues(missInfo.missValue("1007MV_Z36").get(0));
                    ballView_zu3_single.setMissValues(missInfo.missValue("1007MV_Z36").get(0));
                    break;
                case 5:
                    ballView_one.setMissValues(missInfo.missValue("1007MV_Z36").get(0));
                    break;
                case 6:
                    ballView_one.setMissValues(missInfo.missValue("1007MV_Z36").get(0));
                    break;
                case 7:
                case 8:
                    ballView_one.setMissValues(missInfo.missValue("1007MV_5X").get(0));
                    ballView_two.setMissValues(missInfo.missValue("1007MV_5X").get(1));
                    ballView_three.setMissValues(missInfo.missValue("1007MV_5X").get(2));
                    ballView_four.setMissValues(missInfo.missValue("1007MV_5X").get(3));
                    ballView_five.setMissValues(missInfo.missValue("1007MV_5X").get(4));
                    break;
                case 9:
                    ballView_dxds_shi.setMissValues(missInfo.missValue("1007MV_DD").get(0));
                    ballView_dxds_ge.setMissValues(missInfo.missValue("1007MV_DD").get(1));
                    break;

            }
        } else {
            ballView_one.setMissValues(new ArrayList<Integer>());
            ballView_two.setMissValues(new ArrayList<Integer>());
            ballView_three.setMissValues(new ArrayList<Integer>());
            ballView_four.setMissValues(new ArrayList<Integer>());
            ballView_five.setMissValues(new ArrayList<Integer>());
            ballView_dxds_shi.setMissValues(new ArrayList<Integer>());
            ballView_dxds_ge.setMissValues(new ArrayList<Integer>());
            ballView_zu3_double.setMissValues(new ArrayList<Integer>());
            ballView_zu3_single.setMissValues(new ArrayList<Integer>());
        }

    }

    @Override
    protected void net() {
        topView.startRightAnim();
        super.net();
    }

    @Override
    public Intent getTrendIntent() {
        Intent intent = new Intent(getContext(), SSCTrendActivity.class);
        intent.putExtra(IntentParamUtils.LOTTERYID, getLotteryId());
        return intent;
    }
}
